home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Deutsche Edition 1
/
Deutsche Edition 1.iso
/
amok
/
amok_lha
/
amok24.lha
/
Updates
/
ExDos.mod
next >
Wrap
Text File
|
1993-08-15
|
4KB
|
158 lines
(**********************************************************************
:Program. ExDos.mod
:Contents. Dos operations, safe and tolerant
:Author. Nicolas Benezan [bne]
:Address. Postwiesenstr. 2, D7000 Stuttgart 60
:Phone. 711/333679
:Copyright. Public Domain
:Language. Modula-2
:Translator. M2Amiga AMSoft V3.2d
:History. V1.0b [bne] 24.Apr.1989
:History. V1.1a [bne] 13.Aug.1989 (startup modified)
**********************************************************************)
IMPLEMENTATION MODULE ExDos;
FROM Arts IMPORT Assert, TermProcedure;
FROM Exec IMPORT AllocMem, CopyMemQuick, FindTask, FreeMem,
MemReqSet;
FROM SYSTEM IMPORT ADR, BYTE, CAST, LONGSET, SETREG;
IMPORT Dos;
CONST
UnLockNoLock = "ExDos: UnLocked unknown lock";
UnLockCurrentDir= "ExDos: UnLocked current dir";
StartupFail = "ExDos. startup failure";
TYPE
FileLockNodePtr = POINTER TO FileLockNode;
FileLockNode=RECORD
next:FileLockNodePtr;
lock:Dos.FileLockPtr;
END;
VAR
Root:FileLockNodePtr;
Info:RECORD pad1,pad2,pad3:BYTE; block:FileInfoBlock END;
InfoPtr:Dos.FileInfoBlockPtr;
CurrentDir:FileLockPtr;
OriginDir:Dos.FileLockPtr;
Process: Dos.ProcessPtr;
(* $R- $V- $F- *)
PROCEDURE AddLock(DosLock:Dos.FileLockPtr):FileLockPtr;
VAR
Node:FileLockNodePtr;
BEGIN
IF DosLock#NIL THEN
Node:=AllocMem(SIZE(Node^),MemReqSet{});
IF Node#NIL THEN
WITH Node^ DO
next:=Root;
lock:=DosLock;
END;
Root:=Node;
RETURN DosLock;
ELSE
Dos.UnLock(DosLock);
END;
END;
RETURN NIL;
END AddLock;
PROCEDURE Lock(Name:ARRAY OF CHAR;Mode:LockMode):FileLockPtr;
BEGIN
RETURN AddLock(Dos.Lock(ADR(Name),Mode));
END Lock;
PROCEDURE UnLock(Lock:FileLockPtr);
VAR
Node,Last:FileLockNodePtr;
BEGIN
IF Lock#NIL THEN
Assert(Lock#CurrentDir,ADR(UnLockCurrentDir));
Node:=Root;
Last:=ADR(Root);
WHILE Node#NIL DO
IF Node^.lock=Lock THEN
Last^.next:=Node^.next; (* remove Node^ *)
Dos.UnLock(Node^.lock);
FreeMem(Node,SIZE(Node^));
RETURN
END;
Last:=Node;
Node:=Node^.next;
END;
Assert(FALSE,ADR(UnLockNoLock));
END;
END UnLock;
PROCEDURE DupLock(Lock:FileLockPtr):FileLockPtr;
BEGIN
RETURN AddLock(Dos.DupLock(Lock));
END DupLock;
PROCEDURE ParentDir(Dir:FileLockPtr):FileLockPtr;
BEGIN
RETURN AddLock(Dos.ParentDir(Dir));
END ParentDir;
PROCEDURE CreateDir(Name:ARRAY OF CHAR):FileLockPtr;
BEGIN
RETURN AddLock(Dos.CreateDir(ADR(Name)));
END CreateDir;
PROCEDURE Examine(Lock:FileLockPtr;VAR Info:FileInfoBlock):BOOLEAN;
BEGIN
IF (Lock#NIL) AND (Dos.Examine(Lock,InfoPtr)) THEN
CopyMemQuick(InfoPtr,ADR(Info),SIZE(Info));
RETURN TRUE;
END;
RETURN FALSE;
END Examine;
PROCEDURE ExNext(Lock:FileLockPtr;VAR Info:FileInfoBlock):BOOLEAN;
BEGIN
IF (Lock#NIL) AND (Dos.ExNext(Lock,InfoPtr)) THEN
CopyMemQuick(InfoPtr,ADR(Info),SIZE(Info));
RETURN TRUE;
END;
RETURN FALSE;
END ExNext;
PROCEDURE SetCurrentDir(Lock:FileLockPtr);
BEGIN
IF Lock#NIL THEN
CurrentDir:=Lock;
SETREG(0,Dos.CurrentDir(Lock));
END;
END SetCurrentDir;
PROCEDURE GetCurrentDir():FileLockPtr;
BEGIN
RETURN CurrentDir;
END GetCurrentDir;
PROCEDURE Cleanup;
BEGIN
SetCurrentDir(OriginDir);
WHILE Root#NIL DO
UnLock(Root^.lock);
END;
END Cleanup;
BEGIN
Root:=NIL;
Process:=CAST(Dos.ProcessPtr, FindTask(NIL));
CurrentDir:=Process^.currentDir;
OriginDir:=CurrentDir;
TermProcedure(Cleanup);
SetCurrentDir(DupLock(OriginDir));
Assert(CurrentDir#OriginDir, ADR(StartupFail));
InfoPtr:=CAST(Dos.FileInfoBlockPtr,
CAST(LONGSET, ADR(Info.block))-LONGSET{0, 1});
END ExDos.